package cn.tedu.oa.reimbursement.service.impl;

import cn.tedu.oa.reimbursement.mapper.ReimbursementMapper;
import cn.tedu.oa.reimbursement.pojo.dto.ReimbursementQuery;
import cn.tedu.oa.reimbursement.pojo.dto.ReimbursementSaveParam;
import cn.tedu.oa.reimbursement.pojo.entity.Reimbursement;
import cn.tedu.oa.reimbursement.pojo.vo.ReimbursementVO;
import cn.tedu.oa.reimbursement.service.ReimbursementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class ReimbursementServiceImpl implements ReimbursementService {
    @Autowired
    ReimbursementMapper reimbursementMapper;
    @Override
    public List<ReimbursementVO> select(ReimbursementQuery reimbursementQuery) {
        log.info("ReimbursementServiceImpl.select()");
        List<ReimbursementVO> list = reimbursementMapper.select(reimbursementQuery);
        return list;
    }

    @Override
    public void save(ReimbursementSaveParam reimbursementtSaveParam) {
        log.info("ReimbursementServiceImpl.save()"+reimbursementtSaveParam);
        Reimbursement reimbursement = new Reimbursement();
        BeanUtils.copyProperties(reimbursementtSaveParam,reimbursement);
        if(reimbursement.getId()==null){
            reimbursement.setCreateTime(new Date());
            reimbursementMapper.insert(reimbursement);
            log.info("新增报销单成功");
        }else{
            reimbursement.setUpdateTime(new Date());
            reimbursementMapper.update(reimbursement);
        }

    }

    @Override
    public void delete(Integer id) {
        log.info("ReimbursementServiceImpl.delete()"+id);
        reimbursementMapper.delete(id);
    }
}
